package Test;

import java.lang.reflect.*;
import java.util.Arrays;

public class 反射机制 {
    public static void gg(int c){
        System.out.println("adsf");
    }
    public static void gg(int c,int b){
        System.out.println("adsf");
    }
     int a=10;
    public void sss(){
        System.out.println("111");
    }
    public static void main(String[] args) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException, InvocationTargetException {
        反射机制 a =new 反射机制();
        Class cl = a.getClass();
        Class componentType =cl.getComponentType();

        Method[] method=a.getClass().getMethods();
        for (Method m : method){
            System.out.println(m.getName());
            if(m.getName()=="gg"&&m.getParameterCount()==1){
                m.invoke(a,2);
            }
            if(m.getName()=="sss"){
                m.invoke(a);
            }
        }

        Constructor[] methods=a.getClass().getDeclaredConstructors();
        for (Constructor m : methods){
            System.out.println(m.getName());

        }
        Field[] methods1=a.getClass().getDeclaredFields();
        for (Field m : methods1){
            System.out.println(m.getName());
//            m.setAccessible(true);
            int c=m.getInt(a);
            System.out.println(c);
        }


    }

}
class copyof{

    public static void main(String[] args) {
        int[] a={1,2,3};
        Class cl = a.getClass();
        Class componentType = cl.getComponentType();
        System.out.println(componentType);
        int length= Array.getLength(a);
        Object newArray=Array.newInstance(componentType,12);
        System.arraycopy(a,0,newArray,0,length);
        System.out.println(Arrays.toString(a));
        System.out.println(Arrays.toString((int[]) newArray));
    }
}
